home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / technical documentation / develop / develop issue 27 / develop issue 27 code / internet config assistant / toolkit / cfonts.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-08  |  4.7 KB  |  219 lines

  1. /*
  2.     File:        CFonts.h
  3.  
  4.     Contains:    Font manager wrapper classes
  5.  
  6.     Written by:    Arno Gourdol
  7.  
  8.     Copyright:    © 1994-1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.  
  13. */
  14.  
  15. #pragma once
  16.  
  17. #ifndef __CFONTS__
  18. #define __CFONTS__
  19.  
  20. #include <Quickdraw.h>
  21. #include <Fonts.h>
  22. #include <Script.h>
  23. #include <TextEdit.h>
  24. #include <TextUtils.h>
  25.  
  26. #include "CRect.h"
  27.  
  28. enum
  29. {
  30.     smNoScript = -10                            // Invalid script code
  31. };
  32.  
  33. typedef enum FontCode
  34. {
  35.     kMonospacedFont = smScriptMonoFondSize,        // Default mono-spaced font (Monaco 9)
  36.     kPreferedFont = smScriptPrefFondSize,        // Prefered font for the script
  37.     kSmallFont = smScriptSmallFondSize,            // Default small font (Geneva 9)
  38.     kSystemFont = smScriptSysFondSize,            // Designate the system font (Chicago 12 for Roman systems)
  39.     kApplicationFont = smScriptAppFondSize,        // Default application font
  40.     kHelpManagerFont = smScriptHelpFondSize        // Default font used by the Help Manager for Balloon help
  41. } FontCode;
  42.  
  43.  
  44.  
  45.  
  46. // Cache for the international resources for the system script
  47. extern Handle gItl0;
  48. extern Handle gItl2;
  49.  
  50.  
  51. class CFontSpec
  52. {
  53. public:
  54.     // constructors
  55.     CFontSpec(void);
  56.     CFontSpec(ScriptCode scriptCode,
  57.               FontCode font);
  58.               
  59.     // destructor
  60.     ~CFontSpec(void);
  61.  
  62.     // mutators
  63.     void SetFont(ScriptCode scriptCode,
  64.                    FontCode font = kSystemFont);
  65.     Boolean SetFont(ScriptCode scriptCode,
  66.                     ConstStr255Param fontName);
  67.     void SetFontID(short font);
  68.     void SetSize(short size);
  69.     void SetStyle(short style);
  70.     void SetMode(short mode);
  71.  
  72.     // accessors
  73.     inline Boolean IsLeftToRight(void) const;
  74.     inline Boolean IsRightToLeft(void) const;
  75.     inline ScriptCode GetScriptCode(void) const;
  76.     inline void GetFont(Str255& fontName) const;
  77.     inline short GetFont(void) const;
  78.     inline short GetSize(void) const;
  79.     inline short GetStyle(void) const;
  80.     inline short GetMode(void) const;
  81.     void GetFontMetrics(short& lineHeight,
  82.                      short& ascent,
  83.                      short& descent);
  84.     inline UInt16 GetLineHeight(void);
  85.                      
  86.     // string manipulation
  87.     void TruncString(short width,
  88.                      Str255 string,
  89.                      TruncCode where = smTruncMiddle);
  90.     short MeasureString(ConstStr255Param string) const;
  91.     void DrawString(ConstStr255Param string) const;
  92.     void DrawText(ConstStr255Param string,
  93.                   const CRect& bounds,
  94.                   short align = teFlushDefault) const;
  95.     TEHandle TENew(void) const;
  96.     void SetPortFont(GrafPtr port) const;
  97.  
  98.     static const CFontSpec& GetSystemFontSpec(void);
  99.     static const CFontSpec& GetSmallFontSpec(void);
  100.     static Handle GetIntlResource(short id);
  101.  
  102.     // Object state changes
  103.     void Save(void);
  104.     void Restore(void);
  105.     void Use(void) const;
  106. private:
  107.  
  108.     // Caches
  109.     ScriptCode FontToScript(short font);
  110.     Boolean SupportCondense(ScriptCode script);
  111.     Boolean ScriptIsRTL(ScriptCode script);
  112.     long ScriptFont(ScriptCode script, short font);
  113.     
  114.     ScriptCode fScript;        // Script of the font
  115.     short fFont;            // Font ID
  116.     short fSize;             // Font size
  117.     short fStyle;            // Font style (bold, italic, etc...)
  118.     short fMode;            // Font mode
  119.  
  120.     short fLineHeight;        // Height of a line of text
  121.     short fAscent;            // Ascent of a line of text
  122.     short fDescent;            // Descent of a line of text
  123.     Boolean fRightToLeft;    // True if the font is a right-to-left font
  124.  
  125.     // Cached information
  126.     // Item on first line is input, second line is output
  127.     static short fFontToScriptCacheFont;
  128.     static ScriptCode fFontToScriptCacheScript;
  129.     
  130.     static ScriptCode fSupportsCondenseCacheScript;
  131.     static Boolean fSupportsCondenseCache;
  132.     
  133.     static ScriptCode fScriptIsRTLCacheScript;
  134.     static Boolean fScriptIsRTLCache;    // True if rtl
  135.     
  136.     static ScriptCode fScriptFontCacheScript;
  137.     static short fScriptFontCacheFont;
  138.     static long fScriptFontCacheFontAndSize;        
  139.  
  140.     static Boolean pSystemFontInited;
  141.     // static CFontSpec pSystemFontSpec;
  142.  
  143.     static Boolean pSmallFontInited;
  144.     // static CFontSpec pSmallFontSpec;
  145.  
  146.     static Handle pItl0;
  147.     static Handle pItl1;
  148.     static Handle pItl2;
  149.  
  150.     static Handle FetchIntlResource(short id);
  151.  
  152. #ifndef NDEBUG
  153.     short fSaveCount;        // Number of times Save() has been called
  154. #endif
  155.  
  156. };
  157.  
  158.  
  159.  
  160. //
  161. //    CFontSpec inlines
  162. //
  163. //
  164.  
  165. inline Boolean CFontSpec::IsLeftToRight(void) const
  166. {
  167.     return !fRightToLeft;
  168. }
  169.  
  170. inline Boolean CFontSpec::IsRightToLeft(void) const
  171. {
  172.     return fRightToLeft;
  173. }
  174.  
  175. inline ScriptCode CFontSpec::GetScriptCode(void) const
  176. {
  177.     return fScript;
  178. }
  179.  
  180. inline void CFontSpec::GetFont(Str255& fontName) const
  181. {
  182.     ::GetFontName(fFont, fontName);
  183. }
  184.  
  185. inline short CFontSpec::GetFont(void) const
  186. {
  187.     return fFont;
  188. }
  189.  
  190. inline short CFontSpec::GetSize(void) const
  191. {
  192.     return fSize;
  193. }
  194.  
  195.  
  196. inline short CFontSpec::GetStyle(void) const
  197. {
  198.     return fStyle;
  199. }
  200.  
  201.  
  202. inline short CFontSpec::GetMode(void) const
  203. {
  204.     return fMode;
  205. }
  206.  
  207. inline UInt16 CFontSpec::GetLineHeight(void)
  208. {
  209.     UInt16 lineHeight;
  210.     UInt16 ascent;
  211.     UInt16 descent;
  212.     
  213.     GetFontMetrics(lineHeight, ascent, descent);
  214.     
  215.     return lineHeight;
  216. }
  217.  
  218.  
  219. #endif